<test>
    <preconditions>
        <table_exists>hits_100m_single</table_exists>
    </preconditions>

    <create_query>
        CREATE TABLE jit_test_memory (
            key UInt64,
            value_1 UInt64,
            value_2 UInt64,
            value_3 UInt64,
            value_4 UInt64,
            value_5 UInt64
        ) Engine = Memory
    </create_query>

    <create_query>
        CREATE TABLE jit_test_merge_tree (
            key UInt64,
            value_1 UInt64,
            value_2 UInt64,
            value_3 UInt64,
            value_4 UInt64,
            value_5 UInt64
        ) Engine = MergeTree
        ORDER BY key
    </create_query>

  	<create_query>
        CREATE TABLE jit_test_memory_nullable (
            key UInt64,
            value_1 Nullable(UInt64),
            value_2 Nullable(UInt64),
            value_3 Nullable(UInt64),
            value_4 Nullable(UInt64),
            value_5 Nullable(UInt64)
        ) Engine = Memory
    </create_query>

    <create_query>
        CREATE TABLE jit_test_merge_tree_nullable (
            key UInt64,
            value_1 Nullable(UInt64),
            value_2 Nullable(UInt64),
            value_3 Nullable(UInt64),
            value_4 Nullable(UInt64),
            value_5 Nullable(UInt64)
        ) Engine = MergeTree
        ORDER BY key
    </create_query>

    <substitutions>
        <substitution>
            <name>table</name>
            <values>
                <value>jit_test_memory</value>
                <value>jit_test_merge_tree</value>
                <value>jit_test_memory_nullable</value>
                <value>jit_test_merge_tree_nullable</value>
            </values>
        </substitution>
    </substitutions>

    <fill_query>
        INSERT INTO {table}
        SELECT
            number,
            rand64(0),
            rand64(1),
            rand64(2),
            rand64(3),
            rand64(4)
        FROM
            system.numbers_mt
        LIMIT 10000000
    </fill_query>

    <query>
        SELECT
            *
        FROM {table}
        ORDER BY value_1 ASC
        FORMAT Null
    </query>

    <query>
        SELECT
            *
        FROM {table}
        ORDER BY value_1 ASC, value_2 DESC, value_3 ASC
        FORMAT Null
    </query>

    <query>
        SELECT
            *
        FROM {table}
        ORDER BY value_1 ASC, value_2 DESC, value_3 ASC, value_4 DESC, value_5 ASC
        FORMAT Null
    </query>

    <query>
        SELECT
            WatchID
        FROM hits_100m_single
        ORDER BY WatchID ASC, CounterID DESC, ClientIP ASC
        LIMIT 2000000
        FORMAT Null
    </query>

    <query>
        SELECT
            WatchID
        FROM hits_100m_single
        ORDER BY WatchID ASC, CounterID DESC, ClientIP ASC, IPNetworkID DESC, SearchEngineID ASC
        LIMIT 2000000
        FORMAT Null
    </query>

    <drop_query>DROP TABLE IF EXISTS {table}</drop_query>

</test>
